package com.milorad.ads.pages.admin;

import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;

import com.milorad.ads.data.dao.interfaces.CityDao;
import com.milorad.ads.data.domain.City;
import com.milorad.ads.pages.BasePage;

public class CreateEditCityPage extends BasePage {
		
	@SpringBean
	private CityDao cityDao;
	
	public CreateEditCityPage(City city) {				
		
		Form<City> form = new Form<City>("addCityForm", new CompoundPropertyModel<City>(city)) {

			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmit() {				
				
				City city = getModelObject();								
				
				cityDao.save(city);
				
				setResponsePage(CitiesAdministrationPage.class);
			}			
		};
		
		form.add(new TextField<City>("name").setRequired(true));
		
		add(form);	
		
		add (new BookmarkablePageLink<Void>("adminPanelLink", MainAdminPage.class));
		add (new BookmarkablePageLink<Void>("citiesAdministrationLink", CitiesAdministrationPage.class));
	}
}